<template>
  <div class="mr-pt-midBtn"  v-loading="loading">
    <el-button size="mini" type="primary" @click="partStart = true,whichReturnOrder = 'noManufacturer',titleText = '成品所在单位发起'">成品所在单位发起</el-button>
    <el-button size="mini" type="primary" @click="partOrderSubmit">提交</el-button>
    <el-button size="mini" type="primary" @click="cheakDataLength">修改</el-button>
    <el-button size="mini" type="primary" @click="prReturnListDelete">删除</el-button>
    <el-button size="mini" type="primary" @click="frtHcxIssue">缓存箱出库</el-button>
    <el-button size="mini" type="primary" @click="frtHcxScan">缓存箱扫码</el-button>
    <el-button size="mini" type="primary" @click="frtMaterialOut">物料出库</el-button>
    <el-button size="mini" type="primary" @click="frtHcxBack" style="margin-right:5px">缓存箱回库</el-button>
    <!-- <el-button size="mini" type="primary" @click="createCoordinateList"  style="margin-right:5px">创建协调单</el-button> -->
    <el-input
      ref="saomaInput"
      size="mini"
      v-model="indexTm"
      placeholder="请输入条码"
      @keyup.enter.native="saomaEnter"
    ></el-input>
    <!-- <div class="createCoordinateList">
      <div class="cclist-close" @click="cclistClose">
        x
      </div>
      <div class="cclist-list">
        条码 问题类型（） 问题内容qContent
        <ul>
          <li style="margin-top:80px">
            <span style="margin-left:31px">条码：</span>
            <el-input
              size="mini"
              v-model="cclist.barcode"
              placeholder="请输入内容"
              
            ></el-input>
          </li>
          <li>
            <span>问题类型：</span>
            <el-select size="mini" v-model="cclist.problemType" placeholder="请选择">
              <el-option
                v-for="item in cclistQtype"
                :key="item.value"
                :label="item.label"
                :value="item.label"
              >
              </el-option>
            </el-select>
          </li>
          <li>
            <span>问题内容：</span>
            <el-input
              size="mini"
              v-model="cclist.problemContent"
              placeholder="请输入内容"
              
            ></el-input>
          </li>
          <li style="text-align:center">
            <el-button size="mini" type="primary" style="width:80px" @click="cclistSave">保存</el-button>
          </li>
        </ul>
      </div>
    </div> -->
    <el-dialog class="mr-pr-returnOrderBox" :title="titleText" :visible.sync="partStart">
      <el-form :model="form">
        <div style="width:95%;margin-left:2.5%;">
          <TableTitle>
            <slot>
              <p>
                查询条件
              </p>
            </slot>
          </TableTitle>
          <div style="margin:5px 0">
            <el-button size="mini" type="primary" @click="orderSearch">查询</el-button>
            <el-button size="mini" type="primary" @click="reOrderSearch">重置</el-button>
          </div>
          <div class="mr-pt-topSearchs">
            <ul>
              <li>
                <el-input
                  size="mini"
                  v-model="jixing"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>机型：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="pici"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>批次：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="startjiaci"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>起始架次：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="endjiaci"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>截止架次：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="wuliaoNum"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>物料编码：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="tuhao"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>图号：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="qualityNum"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>质量编号：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="returnzt"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>交接状态：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="returnType"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>交接类型：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="returndh"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>交接单号：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="returnDwJm"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>移交单位简码：</span>
              </li>
              <li>
                <el-input
                  size="mini"
                  v-model="receiveDwJm"
                  placeholder="请输入内容"
                   
                ></el-input>
                <span>接收单位简码：</span>
              </li>
            </ul>
          </div>
        </div>
        <div class="mr-pt-searchTable">
          <TableTitle>
            <slot>
              <p>
                交接单信息
              </p>
            </slot>
          </TableTitle>
          <div class="mr-pt-TableBox">
            <el-table
            ref="receiveTable"
            size="mini"
            :data="resData"
            @selection-change="handleSelectionChange"
            style="width: 100%"
            height="220"
            >
              <el-table-column type="selection" width="40"> </el-table-column>
              <el-table-column
                prop="wmsDeliveryPlanId"
                label="交接单号"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              <el-table-column
                prop="itemCode"
                label="物料编码"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              <el-table-column
                prop="itemCode"
                label="图号"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              <el-table-column
                prop="itemName"
                label="物料名称"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="qualityCode"
                label="质量编号"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="supplyRegularNo"
                label="合格证号"
                :show-overflow-tooltip="true"
                width="120"
              >
              </el-table-column>
              <el-table-column
                prop="deliveryQty"
                label="接收数量"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="maxQty"
                label="最大可退数量"
                :show-overflow-tooltip="true"
                width="100"
              >
              </el-table-column>
              <el-table-column
                prop="usableQty"
                label="当前可用数量"
                :show-overflow-tooltip="true"
                width="100"
              >
              </el-table-column>
              <el-table-column
                prop="productCode"
                label="机型"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="batchNo"
                label="批次"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="startLotNo"
                label="起始架次"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="endLotNo"
                label="截止架次"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="receiveDate"
                label="接收日期"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="接收单位"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="receiveEmpCode"
                label="接收人"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="receiveRemark"
                label="接收备注"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="配送数量"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="deliveryDate"
                label="配送日期"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              <el-table-column
                prop="deliveryDeptId"
                label="配送单位"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="deliveryUserId"
                label="配送人"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="deliveryNote"
                label="移交方意见"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="itemPlaneQty"
                label="单机数"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="计量单位"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="marque"
                label="牌号"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="specs"
                label="规格"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="父件图号"
                :show-overflow-tooltip="true"
                width="120"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="成品型号"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="父件型号"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="aoNo"
                label="AO代码"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="isPaper"
                label="是否带纸质质量证明"
                :show-overflow-tooltip="true"
                width="170"
              >
              </el-table-column>
              <el-table-column
                prop="remark"
                label="备注"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="substituteCode"
                label="保留单号"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="限用机型"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="限用批次"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="限用架次"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="zanwu"
                label="限用说明"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                prop="sealDate"
                label="油封期"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              <el-table-column
                prop="maxStorageDate"
                label="最长保管期"
                :show-overflow-tooltip="true"
                width="160"
              >
              </el-table-column>
              
            </el-table>
            <!-- 分页 -->
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNumber"
              :page-sizes="[10,20,50,100]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount">
            </el-pagination>
          </div>
          <div class="mr-pt-returnListBox">
            <TableTitle class="mr-pt-returnListTitle">
              <slot>
                <p>
                  退库单信息
                </p>
              </slot>
            </TableTitle>
            <div>
              <el-button size="mini" type="primary" @click="prOrderPreservations">保存</el-button>
              <el-button size="mini" type="primary" @click="preOrderPreservations">重置</el-button>
            </div>
            <div class="mr-pt-returnListInfo">
                <ul>
                  <li>
                    <el-select size="mini" v-model="value4" placeholder="请选择">
                      <el-option
                        v-for="item in returnListForm.returnType"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                    <span>退库类型：</span>
                  </li>
                  <li>
                    <el-input
                      size="mini"
                      v-model="returnListForm.returnNumber"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>退库数量：</span>
                  </li>
                  <li>
                    <el-input
                      size="mini"
                      v-model="returnListForm.returnBasis"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>退库依据：</span>
                  </li>
                  <li>
                    <el-input
                      :disabled="true"
                      size="mini"
                      v-model="returnListForm.belongCompany"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>零件所在单位：</span>
                  </li>
                  <li>
                    <el-input
                      size="mini"
                      v-model="returnListForm.faultPhenomenon"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>故障现象：</span>
                  </li>
                  <li>
                    <el-input
                      size="mini"
                      v-model="returnListForm.appearanceStatus"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>实物外观状态：</span>
                  </li>
                  <li>
                    <el-input
                      size="mini"
                      v-model="returnListForm.supportingStatus"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>实物配套状态：</span>
                  </li>
                  <li>
                     <el-date-picker
                        size="mini"
                        v-model="returnListForm.MaxStoragePeriod"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        default-time="12:00:00"
                      ></el-date-picker>
                    <span>最长保管期：</span>
                  </li>
                  <li>
                    <el-date-picker
                        size="mini"
                        v-model="returnListForm.oilSealPeriod"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        default-time="12:00:00"
                      ></el-date-picker>
                    <span>油封期：</span>
                  </li>
                  <li>
                    <el-input
                      size="mini"
                      v-model="returnListForm.remark"
                      placeholder="请输入内容"
                       
                    ></el-input>
                    <span>备注：</span>
                  </li>
                  <li style="width:290px">
                    <el-select size="mini" style="width:90px" v-model="value5" placeholder="请选择">
                      <el-option
                        v-for="item in returnListForm.returnPlan"
                        :key="item.value"
                        :label="item.label"
                        :value="item.label"
                        
                      >
                      </el-option>
                    </el-select>
                    <span>是否按原分工生成返修计划：</span>
                  </li>
                </ul>
            </div>
          </div>
        </div>
      </el-form>
    </el-dialog>
    <el-dialog title="退库单修改" :visible.sync="prReturnListUpdate">  
      <div class="mr-pr-modifyOrder">
        <el-button size="mini" type="primary" @click="checkOrderList">保存</el-button>
        <ul>
            <li>
              <el-select size="mini" v-model="updateValue" placeholder="请选择">
                <el-option
                  v-for="item in modifyReturnOrder.returnType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label"
                >
                </el-option>
              </el-select>
              <span>退库类型：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.returnNumber"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>退库数量：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.returnBasis"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>退库依据：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.faultPhenomenon"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>故障现象：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.belongCompany"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>零件所在单位：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.appearanceStatus"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>实物外观状态：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.supportingStatus"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>实物配套状态：</span>
            </li>
            <li>
              <el-input
                size="mini"
                v-model="modifyReturnOrder.remark"
                placeholder="请输入内容"
                 
              ></el-input>
              <span>备注：</span>
            </li>
          </ul>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { frtOrderSearch,prOrderPreservation,prOrderCheck,prOrderDelete,prOrderSubmit,prHcboxIssue,prMaterialOut,prtFrtHcxScan,bufferBoxPrtOut,bufferBoxPrtBack } from '@/utils/api.js'
import TableTitle from "../../../../../components/TableTitle.vue"
export default {
  name: "MrPtMidBtn",
  components:{
    TableTitle
  },
  watch:{
     
  },
  data() {
    return {
      // 创建协调单内的input数据
      cclist:{
          barcode:'',
          problemType:'',
          problemContent:''
        },
      cclistQtype:[
        {
          value: "1",
          label: "问题一",
        },
        {
          value: "2",
          label: "问题二",
        },
        {
          value: "3",
          label: "问题三",
        }
      ],
      loading:false,
      // 判断点击的是零件所在单位发起还是制造单位发起
      whichReturnOrder:'',
      // 点击不同发起给不同标题
      titleText:'',
      // 当前页数
      pageNumber: 1,
      // 数据总个数
      totalCount: 0,
      // 返回的数据数组
      resData: [],
      // 每页数据个数
      pageSize: 10,
      // 缓存箱条码
      hcxTM:'',
      hcxTmList:[],
      // 零件所在单位发起框
      partStart: false,
      // 退货单修改弹出框
      prReturnListUpdate: false,
      // 零件所在单位发起框数据
      form: {
        refusrReson: "",
        // region:'',
        // delivery:false,
        // type:[],
        // desc:''
      },
      // 零件所在单位发起框样式
      formLabelWidth: "50px",
      options1: [
        {
          value: "选项1",
          label: "歼十",
        },
        {
          value: "选项2",
          label: "歼十",
        },
      ],
      options2: [
        {
          value: "选项1",
          label: "厂一",
        },
        {
          value: "选项2",
          label: "厂二",
        },
      ],
      options3: [
        {
          value: "选项1",
          label: "状态一",
        },
        {
          value: "选项2",
          label: "状态二",
        },
      ],
      // 物料编码
      wuliaoNum: "",
      // 交接单号
      returndh: "",
      // 退库移交单位
      returnyjdw: "",
      // 退库接收单位
      returnjsdw: "",
      // 图号
      tuhao: "",
      // 机型
      jixing:'',
      //  批次
      pici: "",
      //  起始架次
      startjiaci: "",
      //  截止架次
      endjiaci: "",
      // 质量编号
      qualityNum: "",
      // 成品型号
      finishType: "",
      // 移交单位简码
      returnDwJm: "",
      // 接收单位简码
      receiveDwJm: "",
      // 零件图号
      partTuHao:"",
      // 父件型号
      fatherType:"",
      // 交接类型
      returnType: "",
      // 退库状态
      returnzt: "",
      // 申请人
      sqPerson: "",
      // 开始时间
      startTime: "",
      // 结束时间
      endTime: "",
      // 物料类型
      wuliaoType: "",
      // 下拉
      value1: "",
      value2: "",
      value3: "",
      value4: "",
      returnListForm:{
        returnType:[
          {
            value: "1",
            label: "无故障退库",
          },
          {
            value: "2",
            label: "执行质量通知单退库",
          },
          {
            value: "3",
            label: "故障单退库",
          }
        ],
        returnPlan:[
          {
            value: "1",
            label: "是",
          },
          {
            value: "2",
            label: "否",
          },
        ],
        returnNumber:'',
        returnBasis:'',
        belongCompany:520,
        faultPhenomenon:'',
        appearanceStatus:'',
        supportingStatus:'',
        MaxStoragePeriod:'',
        oilSealPeriod:'',
        remark:'',
        // 存储hcx扫码的物料信息 物料确认需要
        hcxMaterialInfo:[]
      },
      modifyReturnOrder:{
        returnType:[
          {
            value: "选项1",
            label: "类型一",
          },
          {
            value: "选项2",
            label: "类型二",
          }
        ],
        returnNumber:'',
        returnBasis:'',
        faultPhenomenon:'',
        belongCompany:'',
        appearanceStatus:'',
        supportingStatus:'',
        remark:''
      },
      buttomValue:'',
      updateValue:'',
      // 保存order中表格勾选的信息
      prOrderMidTable:{
        itemCode:'',
        wmsDeliveryPlanId:''
      },
      // 保存Table勾选数据的退货单ID
      wmsReturnApplyId:[],
      // 保存修改按钮中一条数据的退货单ID
      ApplyId:'',
      // 接收indexTable信息，修改按钮
      materialHcxDataInfo:[],
      // 接收index表格勾选的数据  物料出库信息
      materialOutList:[],
      isBoxBack:false,
      loginPersonInfo:{
        account:'',
        empinfoid:'',
        text:'',
        departid:''
      },
      value5:'',
      wloutInfo:'',
      hcxBackData:'',
      hcxComeData:[],
      tListMaxNum:'',
      idStatusList:[],
      indexTm:''
    };
  },
  methods: {
    // 重置零件发起退货单上表查询按钮form
    reOrderSearch(){
      this.fatherType = ''
      this.finishType = ''
      this.partTuHao = ''
      this.receiveDwJm = ''
      this.returnDwJm = ''
      this.returndh = ''
      this.returnType = ''
      this.returnzt = ''
      this.wuliaoType = ''
      this.qualityNum = ''
      this.tuhao = ''
      this.wuliaoNum = ''
      this.endjiaci = ''
      this.startjiaci = ''
      this.pici = ''
      this.jixing = ''
    },
    // 零件发起退货单上表查询按钮
    orderSearch(){

      if(this.whichReturnOrder == 'noManufacturer'){
        // 零件所在单位发起
        frtOrderSearch({
          searchParams:{
            productCode:this.jixing,
            batchNo:this.pici,
            startLotNo:this.startjiaci,
            endLotNo:this.endjiaci,
            itemCode:this.wuliaoNum,
            itemCode:this.tuhao,
            qualityCode:this.qualityNum,
            deliveryStatus:this.returnzt,
            deliveryType:this.returnType,
            deliveryPlanCode:this.returndh,
            deliveryOrgCode:this.returnDwJm,
            receiveOrgCode:this.receiveDwJm,
            // itemCode:this.partTuHao,
            // mProductNumber:this.finishType,
          },
          pageParameter:{
            rows:this.pageSize,
            page:this.pageNumber
          }
        }).then((res)=>{
          // 拿到的数据传给order的表中
          this.resData = res.data.responseBody.result
          console.log('零件发起单位退货单查询按钮',res)
        })
      }else if(this.whichReturnOrder == 'isManufacturer'){
        // 制造单位发起
        console.log('制造单位发起')
      }
      
    },
    // 弹出框-Table勾选函数
    handleSelectionChange(val) {
      this.prOrderMidTable.wmsDeliveryPlanId = val[0].wmsDeliveryPlanId
      this.prOrderMidTable.itemCode = val[0].itemCode
      this.returnListForm.returnNumber = val[0].usableQty
      this.tListMaxNum = val[0].usableQty
      console.log('拿到交接单号和itemCode',this.prOrderMidTable)
    },
    // 零件发起退货单下方重置按钮
    preOrderPreservations(){
      this.value4=''
      this.returnListForm.returnNumber=''
      this.returnListForm.returnBasis=''
      this.returnListForm.belongCompany=''
      this.returnListForm.faultPhenomenon=''
      this.returnListForm.appearanceStatus=''
      this.returnListForm.supportingStatus=''
      this.returnListForm.MaxStoragePeriod=''
      this.returnListForm.oilSealPeriod=''
      this.returnListForm.remark=''
    },
    // 零件发起退货单保存按钮
    prOrderPreservations(){
      this.loginPersonInfo.account = sessionStorage.getItem("userName")
      this.loginPersonInfo.empinfoid = sessionStorage.getItem("userJobNumber")
      this.loginPersonInfo.text = sessionStorage.getItem("userUnits")
      this.loginPersonInfo.departid = sessionStorage.getItem("userUnitsNumber")
      prOrderPreservation({
        account:this.loginPersonInfo.account,
        empinfoid:this.loginPersonInfo.empinfoid,
        text:this.loginPersonInfo.text,
        departid:this.loginPersonInfo.departid,
        itemCode:this.prOrderMidTable.itemCode,
        // 交接单号
        wmsDeliveryPlanId:this.prOrderMidTable.wmsDeliveryPlanId,
        // 退库类型
        returnType:this.value4,
        // 退库数量:
        returnQty:this.returnListForm.returnNumber,
        // 退库依据
        accordingNo:this.returnListForm.returnBasis,
        // 零件所在单位
        // 没有接收字段:this.modifyReturnOrder.belongCompany,
        // 故障现象:
        failureDesc:this.returnListForm.faultPhenomenon,
        // 实物外观状态:
        appearanceStatus:this.returnListForm.appearanceStatus,
        // 实物配套状态:
        equipStatus:this.returnListForm.supportingStatus,
        // 最长保管期:
        maxStorageDate:this.returnListForm.MaxStoragePeriod,
        // 油封期:
        sealDate:this.returnListForm.oilSealPeriod,
        // 备注:
        remark:this.returnListForm.remark,
        // 按原分工生成返修计划:ynWorkLineFlag
        ynWorkLineFlag:this.value5,
      }).then((res)=>{
        console.log('零件发起单位退货单保存按钮',res)
        if(res.data.retCode == 200) {
           this.$Alert({
            title: "成功",
            message: '退货单创建保存成功！',
            type: "success",
          });
          
          // 连接Search统查Table
          this.$bus.$emit('finIndexAllSarch','allSearch')
        }
      })
      
      
    },
    // 分页---每页条数
    handleSizeChange(val){
      this.pageSize = val
      frtOrderSearch({
          searchParams:{
            productCode:this.jixing,
            batchNo:this.pici,
            startLotNo:this.startjiaci,
            endLotNo:this.endjiaci,
            itemCode:this.wuliaoNum,
            itemCode:this.tuhao,
            qualityCode:this.qualityNum,
            deliveryStatus:this.returnzt,
            deliveryType:this.returnType,
            deliveryPlanCode:this.returndh,
            deliveryOrgCode:this.returnDwJm,
            receiveOrgCode:this.receiveDwJm,
            // itemCode:this.partTuHao,
            // mProductNumber:this.finishType,
          },
          pageParameter:{
            rows:this.pageSize,
            page:this.pageNumber
          }
        }).then((res)=>{
          // 拿到的数据传给order的表中
          this.resData = res.data.responseBody.result
          console.log('分页',res)
        })
    },
    // 分页---页数
    handleCurrentChange(val) {
      this.pageNumber = val
      frtOrderSearch({
          searchParams:{
            productCode:this.jixing,
            batchNo:this.pici,
            startLotNo:this.startjiaci,
            endLotNo:this.endjiaci,
            itemCode:this.wuliaoNum,
            itemCode:this.tuhao,
            qualityCode:this.qualityNum,
            deliveryStatus:this.returnzt,
            deliveryType:this.returnType,
            deliveryPlanCode:this.returndh,
            deliveryOrgCode:this.returnDwJm,
            receiveOrgCode:this.receiveDwJm,
            // itemCode:this.partTuHao,
            // mProductNumber:this.finishType,
          },
          pageParameter:{
            rows:this.pageSize,
            page:this.pageNumber
          }
        }).then((res)=>{
          // 拿到的数据传给order的表中
          this.resData = res.data.responseBody.result
          console.log('分页',res)
        })
    },
    // 提交按钮----提交按钮
    partOrderSubmit(){
      prOrderSubmit({
        data:this.idStatusList
      }).then((res)=>{
        if(res.data.retCode == 200){
          // 连接Search统查Table
          this.$bus.$emit('finIndexAllSarch','allSearch')
          console.log('提交按钮',res)
          this.$Alert({
            title: "成功",
            message: '数据提交成功！',
            type: "success",
          });
        }else {
          console.log('提交按钮失败',res)
          this.$Alert({
            title: "失败",
            message: '数据提交失败！',
            type: "error",
          });
        }
      })
    },
    // 点击修改按钮-判断勾选数据条数是否为1 且该数据状态可修改 再打开弹窗
    cheakDataLength(){
      if(this.wmsReturnApplyId.length == 1){
        this.applyID = this.wmsReturnApplyId[0]
        if(this.returnStatus[0] == '编辑中'){
          this.ApplyStatus = this.returnStatus[0]
          this.prReturnListUpdate = true
        }else {
          this.$Alert({
            title: "失败",
            message: '当前数据状态无法进行修改！',
            type: "error",
          });
        }
      }else {
        this.$Alert({
            title: "失败",
            message: '请勾选一条数据进行修改！',
            type: "error",
          });
      }
      
    },
    // 退货单修改--保存按钮
    // 调用修改接口成功则调用上方查询接口刷新Table 
    checkOrderList(){
      prOrderCheck({
        returnStatus:this.ApplyStatus,
        wmsReturnApplyId:this.applyID,
        returnType:this.value4,
        returnQty:this.modifyReturnOrder.usableQty,
        accordingNo:this.modifyReturnOrder.returnBasis,
        appearanceStatus:this.modifyReturnOrder.appearanceStatus,
        equipStatus:this.modifyReturnOrder.supportingStatus,
        remark:this.modifyReturnOrder.remark,
        ynWorkLineFlag:this.value5,
        failureDesc:this.modifyReturnOrder.faultPhenomenon
      }).then((res)=>{
        if(res.data.retCode == 200){
          this.$bus.$emit('finIndexAllSarch','allSearch')
          console.log('退货单修改',res)
          this.$Alert({
            title: "成功",
            message: '修改成功！',
            type: "success",
          });
        }else {
          console.log('退货单修改失败',res)
          this.$Alert({
            title: "失败",
            message: '修改失败！',
            type: "error",
          });
        }
      })
    },
    // 退货单删除按钮接口 
    prReturnListDelete(){
      prOrderDelete({
        data:this.idStatusList
        // wmsReturnApplyId:this.wmsReturnApplyId,
        // returnStatus:this.returnStatus
      }).then((res)=>{
        if(res.data.retCode == 200 || res.data.retCode == 202){
          this.$bus.$emit('finIndexAllSarch','allSearch')
          this.$Alert({
            title: "成功",
            message: res.data.message,
            type: "success",
          });
          console.log('退货单删除按钮',res)
        }else {
          console.log('退货单删除失败',res)
          this.$Alert({
            title: "失败",
            message: res.data.message,
            type: "error",
          });
        }
      })
    },
    // 扫码input 回车绑定函数
    saomaEnter(){
      if(this.indexTm.length == 12){
        // 缓存箱扫码
        this.$options.methods.frtHcxScan.bind(this)()
      }else if(this.indexTm == 9001){
          // 缓存箱出库
          this.$options.methods.frtHcxIssue.bind(this)()
        }else if(this.indexTm == 9002){
          // 缓存箱回库
          this.$options.methods.frtHcxBack.bind(this)()
        }else if(this.indexTm == 9005){
          // 物料出库
          this.$options.methods.frtMaterialOut.bind(this)()
        }else {
          // 物料确认 
          for(let pi=0;pi<this.hcxMaterialInfo.length;pi++){
            if(this.indexTm.CPHGZ == this.hcxMaterialInfo[pi].wmsDeliverPlanDTOList[0].mesCheckQualiticationId){
              this.$bus.$emit('mrFrtMarCheckIndex',pi)
              this.$Alert({
                title: "成功",
                message: this.indexTm+'物料已确认',
                type: "success",
              });
              this.indexTm = ''
            }
          }
        } 
    },
    // 缓存箱出库
    frtHcxIssue(){
      bufferBoxPrtOut({
        data:this.hcxComeData
      }).then((res)=>{
        console.log('缓存箱出库',res)
        if(res.data.retCode == 200){
          this.$Alert({
            title: "成功",
            message: '缓存箱出库命令已下发！',
            type: "success",
          });
          // 缓存箱扫码聚焦 并清空
          // this.$refs.saomaInput.value = ''
          this.indexTm = ''
          this.$refs.saomaInput.focus()
          // this.isBoxBack = false
        }else {
          this.$Alert({
            title: "失败",
            message: '缓存箱出库命令下发失败！',
            type: "error",
          });
        }
      })
    },
    // 缓存箱扫码
    frtHcxScan(){
      // 获取下方缓存箱 将其显示
      if(this.indexTm == ''){
        this.$Alert({
            title: "错误",
            message: '条码不能为空！',
            type: "error",
          })
      }else {
        //yebo 增加重复扫缓存箱判断
        if(this.hcxTmList.some(ele=>ele===this.indexTm)){
          this.$Alert({
            title: "错误",
            message: '该缓存箱已经扫码！',
            type: "error",
          })
          return ;
        }
        // 缓存箱扫码按钮接口
        prtFrtHcxScan({
          workbinCode:this.indexTm,
          wmsDeliveryPlanId:this.hcxComeData[0].wmsDeliveryPlanId
        }).then((res)=>{
          console.log('缓存箱扫码',res)
          if(res.data.retCode == 200){

            this.hcxTmList.push(this.indexTm)
            // 将物料箱信息传给BoxInfo组件
            this.$bus.$emit('mrFrthcxInfoBox',res.data.responseBody)
            this.hcxMaterialInfo = res.data.responseBody
            document.querySelector('.mr-frtHcxInfoBox').style.display = 'inline'
            // 缓存箱扫码聚焦 并清空
            // this.$refs.saomaInput.value = ''
            this.$Alert({
              title: "成功",
              message: res.data.message,
              type: "success",
            })
            this.indexTm = ''
            this.$refs.saomaInput.focus();


          }else {
            this.$Alert({
            title: "错误",
            message: '缓存箱扫码失败',
            type: "error",
          })
          }
        })
      }
    },
    // 缓存箱回库
    frtHcxBack(){
      bufferBoxPrtBack({
          workbinCode:this.hcxTmList
        }).then((res)=>{
          console.log('缓存箱回库',res)
          if(res.data.retCode == 200){
            document.querySelector('.mr-frtHcxInfoBox').style.display = 'none'
            this.hcxTmList = []
            this.$Alert({
              title: "成功",
              message: '缓存箱回库命令已下发！',
              type: "success",
            });
            // 缓存箱扫码聚焦 并清空
            // this.$refs.saomaInput.value = ''
            this.indexTm = ''
            this.$refs.saomaInput.focus()
            // 刷新Table
            this.$bus.$emit('finIndexAllSarch','reTable')
            // 让hcxInfo清空hcx框
            this.$bus.$emit('smFrtClearHcxInfo','清空hcxInfo')
          }else {
            this.$Alert({
              title: "失败",
              message: '缓存箱回库命令下发失败！',
              type: "error",
            });
          }
        })
      // this.isBoxBack = true
      // if(this.isBoxBack == true) {
      //   this.$Alert({
      //       title: "成功",
      //       message: '缓存箱回库命令已下发！',
      //       type: "success",
      //     });
      //   this.isBoxBack = false
      // }else {
      //   this.$Alert({
      //       title: "失败",
      //       message: '无法下发缓存箱回库命令！',
      //       type: "error",
      //     });
      // }
    },
    // 物料出库
    frtMaterialOut(){
      this.loading = true;
      prMaterialOut({
        data:this.wloutInfo
      }).then((res)=>{
        this.loading = false;
        console.log('物料出库',res)
        if(res.data.retCode == 200 || res.data.retCode == 202){
          this.$Alert({
            title: "成功",
            message: res.data.message,
            type: "success",
          });
          // 缓存箱扫码聚焦 并清空
          // this.$refs.saomaInput.value = ''
          this.indexTm = ''
          this.$refs.saomaInput.focus();
          //2023-03-08 yebo 修改，零件退库成功刷新界面数据，以及处理缓存箱显示
          // 刷新Table
          this.$bus.$emit('frtReturnSearch','reTable')
          // 让hcxInfo清空hcx框
          this.$bus.$emit('smFrtClearHcxInfo','清空hcxInfo')
          this.$Alert({
            title: "成功",
            message: '物料已出库！',
            type: "success",
          });
        }else {
          this.$Alert({
            title: "失败",
            message: res.data.message,
            type: "error",
          });
        }
      })
    },
  },
  mounted() {
    // 将修改的数据返给Btn 物料出库按钮 
      this.$bus.$on('mrFrWloutInfo',(e)=>{
        this.wloutInfo = e
        // console.log(e,123123)
      })
    // 传给midBtn 物料出库所需
      this.$bus.$on('sendFMaterialOutInfo',(e)=>{
        this.materialOutList = []
        for(let i=0;i<e.length;i++){
        let qqlist = ''
        let wmsDeliveryPlanId = e[i].wmsDeliveryPlanId
        let returnQty = e[i].returnQty
        let itemCode = e[i].itemCode
        qqlist = {'wmsDeliveryPlanId':wmsDeliveryPlanId,'returnQty':returnQty,'itemCode':itemCode}
        this.materialOutList.push(qqlist)
        }
        // console.log(this.materialOutList,4444)
      })
    // 接收Table给的退货单ID给修改按钮
      this.$bus.$on('sendFinReturnOrderID',(e)=>{
        this.wmsReturnApplyId = e.returnOrderID
        // console.log(123123123123,e.returnOrderID[0])
        this.returnStatus = e.returnStatus
        this.idStatusList = []
        // 将id和status配对
        for(let i=0;i<this.returnStatus.length;i++){
          let qqlist = {'wmsReturnApplyId':this.wmsReturnApplyId[i],'returnStatus':this.returnStatus[i]}
          this.idStatusList.push(qqlist)
        }
      })
    // 接收Table勾选的数据 提供缓存箱出库信息
    this.$bus.$on('sendFinHcxInfoVal',(e)=>{
      // 缓存箱出库 info
      this.hcxComeData = []
      // for(let yy=0;yy<e.length;yy++){
      //   this.hcxComeData.push(e[yy].itemCode)
      // }
      for(let ss=0;ss<e.length;ss++){
        let sjlist = {'itemCode':e[ss].itemCode,'returnQty':e[ss].returnQty,'wmsDeliveryPlanId':e[ss].wmsDeliveryPlanId,'returnStatus':e[ss].returnStatus}
        this.hcxComeData.push(sjlist)
      }
      // 缓存箱入库info
      this.hcxBackData = e
    })
    // 物料输入框回车 让index输入框聚焦 清空
    this.$bus.$on('smFrtMatiToBtninput',(e)=>{
      // 缓存箱扫码聚焦 并清空
      // this.$refs.saomaInput.value = ''
      this.indexTm = ''
      this.$refs.saomaInput.focus()
    })
  },
  watch:{
    // 勾选时将比较的数据存入两个部分一个用于比较一个用于改变
    // 退库单信息数量不能大于表中当前可用数量
    'returnListForm.returnNumber':{
      immediate:true,
      deep:true,
      handler:function (val) {
        let maxNumber = this.tListMaxNum
        // console.log(this.returnListForm.returnNumber)
        this.$nextTick(()=>{
          if(this.returnListForm.returnNumber > maxNumber){
            this.$Alert({
              title: "错误",
              message: '退库数量不可大于当前选中数据可用数量！',
              type: "error",
            });
            this.returnListForm.returnNumber = maxNumber
            
          }else if(this.returnListForm.returnNumber <= 0){
            // this.returnListForm.returnNumber = 1
          }
        })
      }
    }
    
  }
};
</script>
<style>
.el-dialog {
  width: 90% !important;
  height: 90% !important;
  margin-top: 20px !important;
  margin-left: 5% !important;
  overflow: scroll;
}
.el-dialog__body {
  padding: 0;
}
</style>
<style scoped>
.mr-pt-midBtn {
  /* margin-top: 10px; */
  position: relative;
  padding: 10px 3px;
}
.mr-pt-searchTable {
  width: 95%;
  margin-left: 2.5%;
  /* border: 1px solid black; */
}
.mr-pt-TableBox {
  text-align: center;
  height: 250px;
}
.mr-pt-returnListTitle {
  margin-bottom: 5px;
}
.inputBox{
  float: left;
  margin-top: 5px;
  width: 21%;
  height: 30px;
  line-height: 30px;
  margin-right: 1%;
  margin-bottom: 5px;
}
.inputBox span {
  float: right;
}
.inputBox div {
  float: right;
}
.dialog-footer {
    margin-top: 100px;
}
.el-select {
  width: 140px;
}
.el-input {
  width: 140px;
}
.mr-pt-topSearchs {
  overflow: hidden;
}
.mr-pt-topSearchs ul li {
  float: left;
  width: 21%;
  height: 30px;
  line-height: 30px;
  margin-right: 1%;
  margin-bottom: 5px;
  overflow: hidden;
}
.mr-pt-topSearchs ul li span {
  float: right;
}
.mr-pt-topSearchs ul li div {
  float: right;
}
.mr-pt-returnListTitle {
  margin-bottom: 5px;
}
.mr-pt-returnListInfo {
  border: 1px solid gray;
  margin-top: 5px;
  width: 100%;
  height: 150px;
}
.mr-pt-returnListInfo ul {
  margin-top: 5px;
}
.mr-pt-returnListInfo ul li{
  float: left;
  width: 22.6%;
  height: 30px;
  line-height: 30px;
  margin-left: 0.6%;
  margin-top: 10px;
}
.mr-pt-returnListInfo ul li span{
  float: right;
}
.mr-pt-returnListInfo ul li div{
  float: right;
}
.mr-pr-modifyOrder {
  border: 1px solid gray;
  margin-top: 5px;
  width: 100%;
  height: 150px;
  padding-bottom: 20px;
}
.mr-pr-modifyOrder  ul {
  margin-top: 10px;
}
.mr-pr-modifyOrder  ul li{
  float: left;
  width: 22.6%;
  height: 30px;
  line-height: 30px;
  margin-left: 0.6%;
  margin-top: 20px;
}
.mr-pr-modifyOrder  ul li span{
  float: right;
}
.mr-pr-modifyOrder  ul li div{
  float: right;
}
.mr-pr-modifyOrder .el-button {
  margin: 10px 0 0 30px;
}
.createCoordinateList {
  width: 700px;
  height: 400px;
  position: relative;
  position: absolute;
  top: -300%;
  left: 20%;
  background: rgb(230, 230, 230);
  z-index: 99;
  display: none;
}
.cclist-close {
  position: absolute;
  top: 5px;
  right: 5px;
  cursor: pointer;
}
.cclist-list ul {
  width: 40%;
  margin-left: 30%;
}
.cclist-list ul li {
  width: 100%;
  margin-top: 20px;
}
</style>